import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  Put,
} from '@nestjs/common';
import { DictService } from './dicts.service';
import { CreateDictDto } from './dto/create-dicts.dto';
import { UpdateDictDto } from './dto/update-dicts.dto';
import { ApiOperation } from '@nestjs/swagger';
import { SearchDto } from '@/common/dto/base-search.dto';
import { Serialize } from '@/common/decorator/serialize.decorator';
import { ResultDictConverterDto } from './dto/result-dicts.dto';
import { IdsDto } from '@/common/dto/ids.dto';

@Controller('dicts')
export class DictController {
  constructor(private readonly dictService: DictService) {}

  @Post()
  @ApiOperation({ summary: '新增字典' })
  @Serialize(ResultDictConverterDto, false)
  create(@Body() createDictDto: CreateDictDto) {
    return this.dictService.create(createDictDto);
  }

  @Get(':id/form')
  @ApiOperation({ summary: '根据id查询' })
  @Serialize(ResultDictConverterDto, false)
  findOne(@Param('id') id: string) {
    return this.dictService.findOne(id);
  }

  @Get('list')
  @ApiOperation({ summary: '字典列表' })
  findList() {
    return this.dictService.findList();
  }

  @Get('page')
  @ApiOperation({ summary: '分页查询' })
  findPage(@Query() query: SearchDto) {
    return this.dictService.findPage(query);
  }

  @Put(':id')
  @ApiOperation({ summary: '修改字典' })
  update(@Param('id') id: string, @Body() updateDictDto: UpdateDictDto) {
    return this.dictService.update(id, updateDictDto);
  }

  @Delete(':ids')
  @ApiOperation({ summary: '删除字典' })
  remove(@Param() ids: IdsDto) {
    return this.dictService.remove(ids);
  }
}
